//
//  calc.m
//  SimpleCalc
//
//  Created by panos on 26/10/10.
//  Copyright 2010 __MyCompanyName__. All rights reserved.
//

#import "calc.h"

@implementation calc

-(void) calculate{
	
	if (operation == 0)
	{
		operation=next_operation;
		a= [tf floatValue];
	}
	
	else if(operation==1)
	{
		operation=next_operation;
		a= [tf floatValue] +a;
		[tf setFloatValue:a];
		
	}
	
	else if(operation==2)
	{
		operation=next_operation;
		a= a - [tf floatValue] ;
		[tf setFloatValue:a];
	}
	
	else if(operation==3)
	{
		operation = next_operation;
		a= a * [tf floatValue];
        [tf setFloatValue:a];
	}
	
	else if(operation==4)
	{
		operation = next_operation;
        a= a / [tf floatValue];
		[tf setFloatValue:a];
	}
	

}

-(IBAction) add:(id)sender
{
	next_operation =1;
    [tf selectText:tf];
		
	[self calculate];
}

-(IBAction) subtract:(id)sender
{
	next_operation =2;
    [tf selectText:tf];
	
	[self calculate];	
}

-(IBAction) multiply:(id)sender
{
    next_operation =3;
    [tf selectText:tf];
    
    [self calculate];	
}

-(IBAction) divide:(id)sender
{
    next_operation =4;
    [tf selectText:tf];
    
    [self calculate];
}

-(IBAction) equals:(id)sender
{
    next_operation = 0;
    [self calculate];

	[tf setFloatValue:a];
    [tf selectText:tf];
}


-(IBAction) clear:(id)sender
{
	a=0;
	operation=0;
    next_operation=0;
    [tf setFloatValue:a];
    [tf selectText:tf];
}



@end
